﻿using System.Linq;
using ArtheaEngine;
using NLog;

namespace ArtheaServer.Commands
{
    public abstract class MoveCommand : Command
    {
        private static readonly Logger log = LogManager.GetCurrentClassLogger();
        private readonly Direction direction;

        protected MoveCommand(Direction dir, string name, string description) : base(name, description)
        {
            direction = dir;
        }

        public override void Execute(Character ch, Argument argument)
        {
            if (ch.Room == null)
            {
                log.Warn("{0} has no room!", ch);
                return;
            }

            Exit exit = ch.Room.Exits.SingleOrDefault(e => e.Name == direction.ToString());

            if (exit == null)
            {
                ch.WriteLine("You cannot find that exit!");
                return;
            }

            ch.Room.Characters.Remove(ch);
            exit.ToRoom.Characters.Add(ch);
            ch.Room = exit.ToRoom;

            using (var look = new LookCommand())
            {
                look.Execute(ch, string.Empty);
            }
        }
    }

    public class NorthCommand : MoveCommand
    {
        public NorthCommand() : base(Direction.North, "north", "Moves your character north.")
        {
            ListPriority = 10;
        }
    }

    public class SouthCommand : MoveCommand
    {
        public SouthCommand() : base(Direction.South, "south", "Moves your character south.")
        {
            ListPriority = 10;
        }
    }

    public class WestCommand : MoveCommand
    {
        public WestCommand() : base(Direction.West, "west", "Moves your character west.")
        {
            ListPriority = 10;
        }
    }

    public class EastCommand : MoveCommand
    {
        public EastCommand() : base(Direction.East, "east", "Moves your character east.")
        {
            ListPriority = 10;
        }
    }
}